/**
 * @file GBMgr.cpp
 * @author Derek Liu (yjkhtddx@sina.com)
 * @brief 国标28181平台控制器
 * @version 0.0.1
 * @date 2020-07-16
 * 
 * @coryright Copyright Sci-Tech Laboratories (c) 2020
 * 
 */

#include "GBMgr.hpp"
#include <string>
#include "SIPServer.hpp"
#include "TaskMgr.hpp"
#include "eXosip2/eXosip.h"
#include "Global.hpp"

GBMgr *GBMgr::instance()
{
    static GBMgr _ins;
    return &_ins;
}

GBMgr::GBMgr()
    : m_bRegok(false)
// ,m_heartbeat("gb_heartbeat")
{
}

GBMgr::~GBMgr()
{
}

void GBMgr::init()
{
    m_localsipcfg.svr_id = g_local_sip_cfg_svr_id;
    m_localsipcfg.svr_domain = g_local_sip_cfg_svr_domain;
    m_localsipcfg.svr_ip = g_local_sip_cfg_svr_ip;
    m_localsipcfg.svr_port = g_local_sip_cfg_svr_port;

    m_remotesipcfg.svr_id = g_remote_sip_cfg_svr_id;
    m_remotesipcfg.svr_domain = g_remote_sip_cfg_svr_domain;
    m_remotesipcfg.svr_ip = g_remote_sip_cfg_svr_ip;
    m_remotesipcfg.svr_port = g_remote_sip_cfg_svr_port;
    m_remotesipcfg.passwd = g_remote_sip_cfg_passwd;
    return;
}

void GBMgr::start()
{
    TaskMgr::instance()->start();
    SIPServer::instance()->init();
    SIPServer::instance()->setLocalConfig(m_localsipcfg.svr_id, m_localsipcfg.svr_ip, m_localsipcfg.svr_port);
    SIPServer::instance()->start("yjkhtddx/0.0.1");

    g_excontext = SIPServer::instance()->GetExosipContext();

    // CRequestManager::instance()->Start();
    // register_online();
    // //启动心跳
    // Infra::ThreadProc proc = bind(&CGB28181SvrManager::heartbeat_proc, this, std::placeholders::_1);
    // m_heartbeat.start(proc);
    // return 0;
}